package com.jymj.utils;

import java.util.Calendar;
import java.util.Date;

/**
 * 月份工具类
 * @author Lzh
 * @date 2021/3/10 14:00
 */
public class MonthUtils {
    /**
     * 判断是否为月末
     * @param date 传入date类型的参数
     * @return  是月末返回true 否则返回 false
     */
    public static boolean  isLastDayOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DATE, (calendar.get(Calendar.DATE) + 1));
        if (calendar.get(Calendar.DAY_OF_MONTH) == 1) {
            return true;
        }
        return false;
    }

    /**
     * 判断是否为月初
     * @param date 传入date类型的参数
     * @return 是月初返回true 否则返回 false
     */
    public static boolean isFirstDayOfMonth(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DATE,calendar.get(Calendar.DATE)+1);
        if(calendar.get(Calendar.DAY_OF_MONTH) == 2){
            return true;
        }else{
            return false;
        }
    }
}
